package model;

import java.io.Serializable;

/**
 * Title: Product.java<br>
 * Description: class for saving product data<br>
 * Created: 05.01.2013<br>
 * Copyright: Copyright (c) 2012<br>
 * Company: Luxoft Corporation
 * 
 * @author Sveta
 * @version $Rev$: , $Date$: , $Author$:
 */

public class Product implements Comparable<Product>, Serializable {
	private transient int id;
	private int bucketId;
	private String name;
	private String productionCountry;
	private int weight;
	private int price;

	/*
	 * @return a string representation of the object
	 */
	@Override
	public String toString() {
		return "\nProduct [id=" + id + ", bucketId=" + bucketId + ", name="
				+ name + ", productionCountry=" + productionCountry
				+ ", weight=" + weight + ", price=" + price + "]";
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public int getBucketId() {
		return bucketId;
	}

	public void setBucketId(int bucketId) {
		this.bucketId = bucketId;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getProductionCountry() {
		return productionCountry;
	}

	public void setProductionCountry(String productionCountry) {
		this.productionCountry = productionCountry;
	}

	public int getWeight() {
		return weight;
	}

	public void setWeight(int weight) {
		this.weight = weight;
	}

	public int getPrice() {
		return price;
	}

	public void setPrice(int price) {
		this.price = price;
	}

	/**
	 * Title: Product.java:compareTo(Product p)<br>
	 * Description: method for comparison<br>
	 * 
	 * @param p
	 *            the object to be compared.
	 * @return a negative integer, zero, or a positive integer as this object is
	 *         less than, equal to, or greater than the specified object.
	 */
	public int compareTo(Product p) {
		if (getId() > p.getId()) {
			return 1;
		} else if (getId() < p.getId()) {
			return -1;
		} else {
			return 0;
		}

	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		result = prime
				* result
				+ ((productionCountry == null) ? 0 : productionCountry
						.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Product other = (Product) obj;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		if (productionCountry == null) {
			if (other.productionCountry != null)
				return false;
		} else if (!productionCountry.equals(other.productionCountry))
			return false;
		return true;
	}

}
